import contextlib
import glob
import hashlib
import json
import math
import os
import random
import shutil
import threading
import time
from itertools import repeat
from multiprocessing.pool import Pool, ThreadPool
from pathlib import Path
from threading import Thread
from urllib.parse import urlparse

import cv2
import numpy as np
import torch
"""
    输入：摄像头rstp地址列表:carameUrlList[],暂时使用摄像头直接调用摄像头
    处理：对每一个url开始一个线程，取帧，处理，输出836330017
"""

class camera:
    def __init__(self,carameUrlList=["0"]):
        print("init>>>",carameUrlList)
        url_threads=[None] * len(carameUrlList)
        for index in range(len(carameUrlList)):
            cap = cv2.VideoCapture(0)
            url_threads[index]=Thread(target=self.process,args=(carameUrlList[index],cap))
            url_threads[index].start()



    def process(self,url,cap):
        print("img_process>>>",url)
        while cap.isOpened():
            success, image = cap.read()
            if success:
                self.img_process(image)
                cv2.waitKey(10)
            else:
                print('WARNING ⚠️ Video stream unresponsive, please check your IP camera connection.')
    def img_process(self,image):
        cv2.imshow('image', image)
